﻿@using System.Text

@{
    Layout = null;

    Dictionary<string, string> attributes = PageData["attributes"];

    attributes["UploadProfile"] = "\"" + ViewBag.Sample.Path.Substring(0, 1).ToLower() + ViewBag.Sample.Path.Substring(1) + "\"";

    if (ViewBag.Project.ViewEngine == ViewEngine.WebForms && ViewBag.Project.Language == CodeLanguage.Cs)
    {
        attributes["OnUploadComplete"] = "\"slickUpload_UploadComplete\"";
    }

    if (ViewBag.Project.ViewEngine == ViewEngine.Mvc || ViewBag.Project.ViewEngine == ViewEngine.Razor)
    {
        attributes["ShowDropZoneOnDocumentDragOver"] = "true";
        attributes["AutoUploadOnSubmit"] = "true";
        attributes["UploadFormId"] = "\"uploadForm\"";

        SampleHelper.RewriteHtmlAttributes(attributes, "", ViewBag.Project.Language);
        SampleHelper.RewriteHtmlAttributes(attributes, "FileSelector", ViewBag.Project.Language);
        SampleHelper.RewriteHtmlAttributes(attributes, "FileList", ViewBag.Project.Language);
        SampleHelper.RewriteHtmlAttributes(attributes, "UploadProgressDisplay", ViewBag.Project.Language);
    }
    
    if (PageData["HasPostProcessStep"] as bool? == true)
    {
        attributes["OnClientUploadSessionProgress"] = "\"onUploadSessionProgress\"";
    }
}
                            @SampleHelper.RenderComponent("SlickUpload", attributes, null, new
                       {
                           SelectorTemplate = (Func<object, HelperResult>)(
                               @<text>
                                    <a class="button">
                                        <span><b class="icon add"></b> Add files</span>
                                    </a>
                                    </text>),
                           SelectorFolderTemplate = (Func<object, HelperResult>)(
                               @<text>
                                    <a class="button">
                                        <span><b class="icon add-folder"></b> Add folder</span>
                                    </a>
                                    </text>),
                           SelectorDropZoneTemplate = (Func<object, HelperResult>)(
                               @<text>
                                    <div>Drag and drop files here.</div>                
                                    </text>),
                           FileItemTemplate = (Func<object, HelperResult>)(
                               @<text>
                                    <div class="filedata">
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileName" })
                                        &ndash;
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.FileSize" }, null, "(calculating)")
                                    </div>
                                        @SampleHelper.RenderComponent("FileListRemoveCommand", null, new { href = "\"javascript:;\"" }, "[x]")
                                        @SampleHelper.RenderComponent("FileListElement", new { Element = "FileListElementType.ValidationMessage" }, new { style = "\"color:#f00\"" })
                                    </text>),
                           ProgressTemplate = (Func<object, HelperResult>)(
                               @<text>
                                        <div id="duringUpload">
                                            <div>
                                                Uploading @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }) file(s),
                                                @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.ContentLengthText" }, null, "(calculating)").
                                            </div>
                                            <div>
                                                Currently uploading: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileName" })
                                                file @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.CurrentFileIndex" })
                                                of @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.FileCount" }).
                                            </div>
                                            <div>
                                                Speed: @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.SpeedText" }, null, "(calculating)")
                                            </div>
                                            <div>
                                                @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.TimeRemainingText" }, null, "(calculating)")
                                            </div>
                                            <div class="progressBarContainer">
                                                @SampleHelper.RenderComponent("UploadProgressBar")
                                                <div class="progressBarText">
                                                    @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.PercentCompleteText" }, null, "(calculating)")
                                                </div>
                                            </div>
                                        </div>
                                        @if (PageData["HasPostProcessStep"] as bool? == true)
                                        {
                                        <div id="postProcessing" style="display:none">
                                            <div>
                                                Post processing files...
                                            </div>
                                            <div class="progressBarContainer">
                                                @SampleHelper.RenderComponent("UploadProgressBar")
                                                <div class="progressBarText">
                                                    @SampleHelper.RenderComponent("UploadProgressElement", new { Element = "UploadProgressElementType.PercentCompleteText" }, null, "(calculating)")
                                                </div>
                                            </div>
                                        </div>                                            
                                        }
                                    </text>)
                       })
                            @if (ViewBag.Project.ViewEngine != ViewEngine.WebForms)
                            {
                            @SampleHelper.RenderComponent("KrystalwareScriptRenderer")
                            }